package com.matt.repository.impl;

import com.matt.repository.base.BaseNativeSqlRepository;
import com.matt.repository.base.StaffMenuRepository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/8/4
 * *******************************
 */
@Service
public class StaffMenuRepositoryImpl extends BaseNativeSqlRepository implements StaffMenuRepository{

    @Override
    public List<Object[]> findMenusByStaff(String staffId) {
        String findTeacherSql=String.format("SELECT m.id, m.pid ,m.name, m.url, m.icon,  m.lvl, m.idx " +
                "from rel_staff_role sr LEFT JOIN rel_role_menu rm ON sr.roleId =rm.roleId LEFT JOIN Menu m ON rm.menuId = m.id " +
                " where sr.staffId = '%s' and m.deleted=false ", staffId);
        List<Object[]> objectArrayList = sqlArrayList(findTeacherSql);
        return objectArrayList;
    }


    @Override
    public List<Object[]> findMenusByRole(String roleId) {
        String findTeacherSql=String.format("SELECT m.id, m.pid ,m.name, m.url, m.icon,  m.lvl, m.idx " +
                "from rel_role_menu rm LEFT JOIN Menu m ON rm.menuId = m.id " +
                " where rm.roleId = '%s' and m.deleted=false ", roleId);
        List<Object[]> objectArrayList = sqlArrayList(findTeacherSql);
        return objectArrayList;
    }
}
